package trans;

import data.DaoFactory;
import data.DaoSession;

public abstract class BaseTransBean {
	private DaoSession daoSession;
	private DaoSession daoSessionBak;
	private boolean remoteFlag;

	protected BaseTransBean(boolean remoteFlag){
		daoSession = DaoFactory.getSession(true);
		if (remoteFlag){
			daoSessionBak = DaoFactory.getSession(false);
		}
		this.remoteFlag = remoteFlag;
	}

	public final static void closeDaoSession(){
		DaoFactory.closeSession();
	}

	protected DaoSession getDaoSession() {
		return daoSession;
	}

	protected DaoSession getDaoSessionBak() {
		return daoSessionBak;
	}
	
	protected boolean isRemoteFlag() {
		return remoteFlag;
	}

	protected void commit(boolean flag){
		daoSession.commit();
		if (flag && remoteFlag){
			daoSessionBak.commit();
		}
	}
	
	protected void rollback(){
		daoSession.rollback();
		if (remoteFlag){
			daoSessionBak.rollback();
		}
	}
}
